﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeGenerator.Common
{
    public static class StringEx
    {
        /// <summary>
        /// 首字母大写
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string FirstCharToUpper(this string text)
        {
            return text.First().ToString().ToUpper() + text.Substring(1);
        }

        /// <summary>
        /// 首字母小写
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string FirstCharToLower(this string text)
        {
            return text.First().ToString().ToLower() + text.Substring(1);
        }

        /// <summary>
        /// 下划线转驼峰
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string LineToHump(this string text)
        {
            StringBuilder builder = new StringBuilder();
            foreach (var s in text.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries))
            {
                builder.Append(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s));
            }
            return builder.ToString();
        }
    }
}
